// my_other/dtphb/dtphb.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    title: '',
    heights: '',
    shopName: '',
    // phType: ['投诉排行', '好评排行'],
    currtab: 0,
    page: 1,
    gongwu: false,
    shop: '',
    tsList: [],
    hpList: [],
  },
  qies(e) {
    shuzong = []
    shu = []
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      page: 1,
      gongwu: false
    })
      this.gettsList()
  },
  // 投诉查看更多
  lookmore0() {
    shuzong = this.data.tsList
    this.setData({
      page: (this.data.page) + 1
    })
    this.gettsList();
  },
  // 好评查看更多
  lookmore1() {
    shuzong = this.data.hpList
    this.setData({
      page: (this.data.page) + 1
    })
    this.gethpList();
  },
  gettsList() {
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Shop/shopScoreRanking', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading()
        shu = res.data.data;
        if (that.data.page != 1) {
          if (shu.length != 10) {
            that.setData({
              gongwu: true
            })
          }
        }
        that.setData({
          tsList: shuzong.concat(shu),
          shop: res.data.thisShop[0]
        })
        console.log(that.data.shop)
        console.log(that.data.tsList)
      }
    })
  },
  gethpList() {
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Shop/shopHaopingRanking', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page
    }, "POST").then(res => {
      if (res.data.code == 200) {
        wx.hideLoading()
        shu = res.data.data;
        if (that.data.page != 1) {
          if (shu.length != 10) {
            that.setData({
              gongwu: true
            })
          }
        }
        that.setData({
          hpList: shuzong.concat(shu),
          shop: res.data.shop
        })
        console.log(that.data.hpList)
      }
    })
  },
  // tousu() {
  //   let arr = this.data.tsList;
  //   arr.forEach(item => {
  //     if (item.name == this.data.shopName) {
  //       this.setData({
  //         tspm: item.pm,
  //         ts: item.ts
  //       })
  //     }
  //   })
  //   this.setData({
  //     tsList: arr
  //   })
  //   console.log(this.data.tsList)
  // },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title,
    })
    this.gettsList();
    // this.tousu();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})